// Pattern based natural language processing tools
// Copyright (C) 2013 University of Tartu
%module pypatnlp

%include "typemaps.i"
%include "std_string.i"
%include "std_vector.i"
%include "std_map.i"
%include "std_set.i"
%include "std_pair.i"
#include "cdata.i"
%include "exception.i"

// wrap C++ standard exceptions
%exception {
    try {
        $action
    }
    catch (const std::runtime_error& e) {
        SWIG_exception(SWIG_RuntimeError, e.what());
    }
    catch (const std::invalid_argument& e) {
        SWIG_exception(SWIG_ValueError, e.what());
    }
    catch (const std::out_of_range& e) {
        SWIG_exception(SWIG_IndexError, e.what());
    }
    catch (...) {
        SWIG_exception(SWIG_RuntimeError, "unknown exception");
    }
}

%{
#include "PatNlp.hpp"
#include "CoverMetrics.hpp"
#include "DocCover.hpp"
#include "Cover.hpp"
#include "Corpus.hpp"
#include "Rule.hpp"
#include "Apriori.hpp"
%}

// mappings from strings to diffrent types of DocCover instances
%template(StrMapOc) std::map<std::string, patnlp::OrderedDocCover>;
%template(StrMapBc) std::map<std::string, patnlp::BitsetDocCover>;

// mapping from strings to CoverMetrics
%template(StrMapMetric) std::map<std::string, patnlp::CoverMetrics>;

%include "include/PatNlp.hpp"
%include "include/CoverMetrics.hpp"
%include "include/DocCover.hpp"
%include "include/Cover.hpp"
%include "include/Corpus.hpp"
%include "include/Rule.hpp"
%include "include/Apriori.hpp"

namespace std {
    // some standard vectors
    %template(LongVector) vector<long>;
    %template(StringVector) vector<string>;
    %template(BoolVector) vector<bool>;

    // some standard maps
    %template(StrMapL) map<string, long>;
    %template(StrMapD) map<string, double>;
    %template(StrMapLv) map<string, vector<long> >;
    %template(StrMapBv) map<string, vector<bool> >;

    // corpus aliases
    %template(Document) vector<vector<string> >;
    %template(Corpus) map<string, vector<vector<string> > >;

    // rules
    %template(Rule) pair<long, string>;
}

namespace patnlp {
    template<class DocCoverType> class Cover;

    // specialize Cover for different DocCover types
    %template(OrderedCover) Cover<OrderedDocCover>;
    %template(BitsetCover) Cover<BitsetDocCover>;
}

namespace std {
    // rules
    %template(Conjunction) vector<pair<long, string> >;
    %template(ConjunctionVector) vector<vector<pair<long, string> > >;
    %template(ConjunctionSet) set<vector<pair<long, string> > >;
    // rule covers
    %template(RuleOrderedDocCover) map<pair<long, string>, patnlp::OrderedDocCover>;
    %template(RuleBitsetDocCover) map<pair<long, string>, patnlp::BitsetDocCover>;
    %template(RuleOrderedCover) map<pair<long, string>, patnlp::Cover<patnlp::OrderedDocCover> >;
    %template(RuleBitsetCover) map<pair<long, string>, patnlp::Cover<patnlp::BitsetDocCover> >;

    %template(RuleCount) map<pair<long, string>, long>;

    //
    %template(OrderedCoverVector) vector<patnlp::Cover<patnlp::OrderedDocCover> >;
    %template(BitsetCoverVector) vector<patnlp::Cover<patnlp::BitsetDocCover> >;
}
